﻿using Foundation;
using Foundation.MarkupExtensions;

namespace Poet.ViewModels
{
    /// <summary>
    /// View model for go to line dialog.
    /// </summary>
    public class GoToLineViewModel : ViewModel
    {
        /// <summary>
        /// Gets or sets the line number.
        /// </summary>
        /// <value>
        /// The line number.
        /// </value>
        public int LineNumber
        {
            get { return Get(() => LineNumber); }
            set { Set(() => LineNumber, value); }
        }

        /// <summary>
        /// Gets or sets the min line number.
        /// </summary>
        /// <value>
        /// The min line number.
        /// </value>
        public int MinLineNumber { get; set; }

        /// <summary>
        /// Gets or sets the max line number.
        /// </summary>
        /// <value>
        /// The max line number.
        /// </value>
        public int MaxLineNumber { get; set; }

        /// <summary>
        /// Gets the validate error message.
        /// </summary>
        /// <param name="propertyName">Name of the property.</param>
        /// <returns></returns>
        protected override string GetDataErrorInfo(string propertyName = null)
        {
            if (propertyName == null || propertyName == GetPropertyName(() => LineNumber))
            {
                if (MinLineNumber > LineNumber || LineNumber > MaxLineNumber)
                {
                    var errorMessage = Localizing.ProvideValue("ValueMustBeInRange");
                    return string.Format("{0}: [{1}-{2}]", errorMessage, MinLineNumber, MaxLineNumber);
                }
            }

            return null;
        }
    }
}
